package cn.wolfcode.luowowo.comment.service.impl;

import cn.wolfcode.luowowo.comment.domain.RemarkComment;
import cn.wolfcode.luowowo.comment.service.IRemarkCommentService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.Date;
import java.util.List;

@Service
public class RemarkCommentServiceImp implements IRemarkCommentService {
    @Autowired
    private MongoTemplate mongoTemplate;
    //保存评论信息
    public void save(RemarkComment remark) {
        if(remark!=null){
            remark.setCrateTime(new Date());
        }
        mongoTemplate.save(remark);
    }
    //根据社区回答的id查询评论信息
    public List<RemarkComment> getRemarkAll(Long uid) {
        Query query = new Query();
        query.addCriteria(Criteria.where("userInfoId").is(uid));
        Sort time = new Sort(Sort.Direction.DESC, "crateTime");
        query.with(time);
        List<RemarkComment> comments = mongoTemplate.find(query, RemarkComment.class);
        return comments;
    }
}
